@model Orchard.ContentTypes.ViewModels.CreateTypeViewModel

@{ Layout.Title = T("New Content Type").ToString(); }

@using (Html.BeginFormAntiForgeryPost()) {
    @Html.ValidationSummary()
    <fieldset>
        <label for="DisplayName">@T("Display Name")</label>
        @Html.TextBoxFor(m => m.DisplayName, new {@class = "textMedium", autofocus = "autofocus"})
        <span class="hint">@T("Name of the type as it will be displayed in screens.")</span>
        <label for="Name">@T("Content Type Id")</label>
        @Html.TextBoxFor(m => m.Name, new {@class = "text"})
        <span class="hint">@T("Technical name of the type.")</span>
    </fieldset>
    <fieldset>
        <button class="primaryAction" type="submit">@T("Create")</button>
    </fieldset>}

@using(Script.Foot()){
<script type="text/javascript">
//<![CDATA[
    $(function(){
        var $name = $("#@Html.FieldIdFor(m=>m.Name)");
        var $displayName = $("#@Html.FieldIdFor(m=>m.DisplayName)");
        var jsonUrl = "@Url.Action("ContentTypeName", "Admin", new RouteValueDictionary { {"Area","Orchard.ContentTypes"} } )";
        var version = 0;

        var nameAltered;
        $name.keypress(function() {
            nameAltered = true;
        });
        
        var compute = function() {
            // stop processing automatically if altered by the user
            if(nameAltered) {
                return true;
            }

            $.post(jsonUrl, {
                    displayName: $displayName.val(),
                    version: ++version,
                    __RequestVerificationToken: $("input[name=__RequestVerificationToken]").val()
                },
                function(data) {
                    if(version == data.version) {
                        $name.val(data.result);
                    }
                },
                "json"
            );
        };
        
        //pull technical name input from tab order
        $name.attr("tabindex", -1);
        
        $displayName.keyup(compute);
        $displayName.blur(compute);
    })
//]]>
</script>
}